
class Scanner {
  constructor(template) {
    this.template = template;

    this.pos = 0;
    this.rest = template;
  }

  /* 走过指定的内容 如{{ }} */
  scan (tag) {
    if (this.rest.indexOf(tag) == 0) {
      this.pos += tag.length;
      this.rest = this.template.substring(this.pos);
    }
  }

  /* 扫描 直到遇到指定的内容，返回 扫描到的内容 */
  scanUtil (stopTag) {
    const _pos = this.pos;

    while (this.rest.indexOf(stopTag) !== 0 && !this.eos()) {
      this.pos++;
      this.rest = this.template.substring(this.pos);
    }

    return this.template.substring(_pos, this.pos);
  }

  /* 指针是否到头 */
  eos () {
    return this.pos >= this.template.length;
  }
}


export {
  Scanner
}